package com.ailink.studentscard.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping
public class PubController {

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index() { return "index"; }

    @RequestMapping(value = "/toModify",method = RequestMethod.GET)
    public String modify() {
        return "modify";
    }

    @RequestMapping(value = "/reglog",method = RequestMethod.GET)
    public String reglog() { return "reglog"; }

    @RequestMapping(value = "/logout",method = RequestMethod.GET)
    public String logout() { return "reglog"; }

    @ResponseBody
    @PostMapping("/register")
    public String register(@RequestParam("username") String username,
                           @RequestParam("realname") String fullname,
                           @RequestParam("stusex") String sex,
                           @RequestParam("password") String password,
                           @RequestParam("password2") String password2,
                           @RequestParam("phone") String phone,
                           @RequestParam("school") String school,
                           @RequestParam("stugrade") String grade,
                           @RequestParam("stutype") String type){
        return username+fullname+phone+type;
    }

    @ResponseBody
    @PostMapping("/login_in")
    public String loinIn(@RequestParam("username") String username,
                         @RequestParam("password") String password) {
        return "{\"msg\":\"登录成功\",\"code\":0,\"data\":{\"uid\":1,\"phone\":\"15982337677\",\"student\":{\"birthday\":\"2018-12-29\",\"stuclass\":\"三年二班\",\"stusex\":\"男\",\"imei\":\"12345678\",\"sch\":{\"schid\":1,\"location\":\"114.421435 30.615061\",\"schname\":\"aaa\"},\"type\":\"住校\",\"stuname\":\"李疯狂\"},\"imei\":\"12345678\",\"state\":\"0\",\"realname\":\"付林琳琳\",\"username\":\"admin\"}}";
    }

    @ResponseBody
    @PostMapping("/modify")
    public String modify(@RequestParam("username") String username){
        return "{\"msg\":\"修改成功\",\"code\":0}";
    }

    @ResponseBody
    @PostMapping("/usernameIsExists")
    public String usernameisExit(HttpServletRequest request){
        System.out.println(request.getQueryString());
        return "{\"msg\":\"成功\",\"code\":0}";
    }

    @ResponseBody
    @PostMapping("/schoolList")
    public String schoolList(){
        return "{\"msg\":\"成功\",\"code\":0,\"data\":[{\"schid\":1,\"schname\":\"aaa\"},{\"schid\":2,\"schname\":\"bbb\"},{\"schid\":3,\"schname\":\"ccc\"}]}";
    }

}
